<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">碎片列表</h3>

        <div class="box-tools pull-right">
            <a href="javascript:;" class="btn btn-sm btn-info btn-flat pull-left" onclick="showEditModel()"><i class="fa fa-fw fa-user-plus"></i> 新增碎片</a>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="table-responsive">
            <table class="table no-margin">
                <thead>
                    <tr>
                        <th>碎片标题</th>
                        <th>碎片类型</th>
                        <th>管理操作</th>
                    </tr>
                </thead>
                <tbody>
                    {volist name="list" id="data"}
                    <tr>
                        <td>{$data.name}</td>
                        <td></td>
                        <td>
                            <a href="javascript:;" class="btn btn-default" onclick='editLink({:json_encode($data)})'>修改</a>
                            |
                            <a href="#" class="btn btn-danger" onclick='confirmDelDefault("{:url("block/delblock",["id"=>$data["id"]])}", "删除操作不能恢复，请谨慎选择")'>删除</a>
                        </td>
                    </tr>
                    {/volist}
                </tbody>
            </table>
        </div>
        <!-- /.table-responsive -->
    </div>
    <!-- /.box-body -->
</div>


<div class="modal fade" id="blockModel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><span>编辑</span>友情碎片</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="blockForm">
                    <input type="hidden"  id="blockId" name="id" value="" />
                    <div class="form-group">
                        <label for="blockTitle" class="col-sm-2 control-label">碎片标题：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="blockTitle" name="name" placeholder="碎片标题">
                        </div>
                    </div>
                    <!--div class="form-group">
                        <label for="blockTypeid" class="col-sm-3 control-label">所属分类：</label>

                        <div class="col-sm-3">
                            <select class="form-control" id="blockTypeid" name="">
                                
                            </select>
                        </div>
                    </div -->
                    <div class="form-group">
                        <label for="introduce" class="col-sm-2 control-label">网站描述：</label>

                        <div class="col-sm-10">
                            <textarea class="form-control" rows="3" id="introduce" placeholder="网站描述 ..." name="data"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="savePosterSpace()">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var editObj;
    /**
     * 显示编辑框
     * @returns {undefined}
     */
    function showEditModel() {
        fromReset('blockForm');
        $("#blockModel").modal('show');
        //editObj.setData('s');
    }

    /**
     * 编辑碎片
     */
    function editLink(info) {
        showEditModel();
        $('#blockId').val(info.id);
        $('#blockTitle').val(info.name);
        editObj.setData(info.data);
        //$('#introduce').val(info.introduce);
    }


    /**
     * 保存内容
     * @returns {Boolean}
     */
    function savePosterSpace() {
        var formData = $('#blockForm').serializeArray();
        var data = {};
        $.each(formData, function () {
            data[this.name] = this.value;
        });
        data.data = editObj.getData();
        console.log(data);
        if (!data.name) {
            toast('提示', '碎片标题不能为空', 1000);
            return false;
        }
        stbAjax('{:url("block/editblock")}', data, function (result) {
            //console.log(result);
            //$("#blockModel").modal('hide');
            toast('提示', result.msg, 1000);
            setTimeout('location.reload()', 500);
        });
    }
    
    $(function () {
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        editObj = CKEDITOR.replace('introduce')
        //bootstrap WYSIHTML5 - text editor
        //$('.textarea').wysihtml5();
      })
    
    
</script>